<?php
if (!defined('ROOT_PATH')) die('No direct access.');
function listBarang($param,$tags,$sort){
	//$db = new db();
	$query = "SELECT idBarang,b.nama AS nama,`slug-nama`,harga,deskripsi,idFB,`nama-toko`,`slug_nama-toko`
		FROM Barang b
		INNER JOIN Pengguna p ON b.idPenjual=p.idPengguna WHERE ";
	$param[1] = (isset($param[1])) ? $param[1] : '';
	switch ($param[1]){
		case "fashion" :
			$query .= "kategori = 1 ";
			break;
		case "elektronik" :
			$query .= "kategori > 1 AND kategori < 5 ";
			break;
		case "kesehatan" :
			$query .= "kategori = 5 ";
			break;
		case "perlengkapan" :
			$query .= "kategori > 5 AND kategori < 9 ";
			break;
		case "seni" :
			$query .= "kategori > 8 AND kategori < 13 ";
			break;
		case "hobi" :
			$query .= "kategori = 13 ";
			break;
		case "kebun" :
			$query .= "kategori = 14 ";
			break;
		case "makanan" :
			$query .= "kategori = 15 ";
			break;
		case "lain" :
			$query .= "kategori=0 ";
			break;
		default:
			$query .= "1 ";
			break;
	}
	//TAGS
	if (count($tags)>0){
		$query .= "AND (";
		for ($i=0; $i<(count($tags)-1); $i++){
			$query .= "keywords LIKE '%".$tags[$i]."%' OR ";
			$query .= "b.nama LIKE '%".$tags[$i]."%' OR ";
		}
		$query .= "keywords LIKE '%".$tags[$i]."%' OR ";
		$query .= "b.nama LIKE '%".$tags[$i]."%' ";
		$query .= ") ";
	}
	//ORDER
	$query .= " ORDER BY ".$sort['tipe']." ".$sort['by'];
	//echo $query;
	//$ret = $db->query($query);
	return $query;
}

function cariBarang($param){}
function sortBarang($param){}
